<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page import="com.yaodian100.core.common.utils.ServerValue"%>
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c-rt"%>
<%@ taglib prefix="s" uri="/struts-tags"%>

<head>
	<style type="text/css">
	h1 span{visibility:visible;}
	td span{visibility:visible;}
	.msg{float:left; line-height:1em; margin:0; display:block;border:1px solid #f66;padding:2px 5px;*padding:2px 5px 1px;}
	.msg.rn{background-color:#fff2f2;border-color:#f66;}
	</style>
</head>

<c-rt:set var="midContextPath" value='<%=ServerValue.getMidContextPath() %>'/>
<c-rt:set var="frontHostname" value='<%=ServerValue.getFrontHostname() %>'/>
<%-- 数字验证 --%>
<script type="text/javascript" charset="UTF-8" src="/js/jquery.alphanumeric.js"></script>
<%-- 月历 --%>
<link rel="stylesheet" type="text/css" href="/css/smoothness.datepick.css" />
<script type="text/javascript" charset="UTF-8" src="/js/jquery.datepick.js"></script>
<script type="text/javascript" charset="UTF-8" src="/js/jquery.datepick-zh-CN.js"></script>
<script type="text/javascript" charset="UTF-8" src="/js/yaodian100.common.js"></script>
<script type="text/javascript" charset="UTF-8" src="/js/jquery.autotab-1.1b.js"></script>

<script>
$().ready( function() {
	$('#subBtn').click(function() {
		if( validate_data() ) {
			$('#creditcardForm').submit();
		}
	});
	
	$('input[id^=tmp_periods_]').click(function() {
		var no = this.id.replace('tmp_periods_', '');
		if(this.checked)
			$('#periods_' + no).val(this.value);
		else {
			$('#periods_' + no).val('');
			$('#fees_' + no).val('');
			$('#downLimits_' + no).val('');
			$('#upLimits_' + no).val('');
		}
	});
	
	$('#bankCode').change(function() {
		if( $('#bankCode').val() != '' ) {
			$('#creditcardForm').attr('action', 'edit.do');
			$('#creditcardForm').submit();
		}
	});
	
	$('input[id^=fees_]').ydPrice();
	$('input[id^=downLimits_]').ydPrice();
	$('input[id^=upLimits_]').ydPrice();
});

function validate_data() {
	var isCorrect = true; <%-- 预设验证正确 --%>
	
	cleanTip();
	/*
	if( $('#creditcardName').val() == '' ) {
		appendTip('creditcardName', '请输入信用卡银行名称', true);
		isCorrect = false;
	}
	*/
	var isPeriodBlank = true;
	for(var i = 0; i < $('input[id^=periods_]').length; i++) {
		var no = i + 1;
		if( $('#tmp_periods_' + no).attr('checked') && $('#periods_' + no).val().length == 0 ) {
			$('#periods_' + no).val( $('#tmp_periods_' + no).val() );
		} else if( !($('#tmp_periods_' + no).attr('checked')) && $('#periods_' + no).val().length > 0 ) {
			$('#periods_' + no).val( '' );
		}
		
		if( $('#periods_' + no).val().length > 0 ) {
			isPeriodBlank = false;
			if( $('#fees_' + no).val().length == 0 ) {
				appendTip('detail', '请输入'+$('#tmp_periods_' + no).val()+'期的会员自付手续费', false);
				isCorrect = false;
			}
			
			if( $('#downLimits_' + no).val().length == 0 || $('#upLimits_' + no).val().length == 0 ) {
				appendTip('detail', '请输入'+$('#tmp_periods_' + no).val()+'期的交易金额上下限', false);
				isCorrect = false;
			} else if( parseFloat($('#downLimits_' + no).val()) > parseFloat($('#upLimits_' + no).val()) ) {
				appendTip('detail', $('#tmp_periods_' + no).val()+'期交易下限金额要小于上限金额', false);
				isCorrect = false;
			}
			
		} else {
			if( $('#fees_' + no).val().length > 0 
					|| $('#downLimits_' + no).val().length > 0
					|| $('#upLimits_' + no).val().length > 0 ) {
				appendTip('detail', '请清除'+$('#tmp_periods_' + no).val()+'期的手续费、交易金额上下限，或选择'+$('#tmp_periods_' + no).val()+'期', false);
				isCorrect = false;
			}
		}
	}
	
	if( isPeriodBlank ) {
		appendTip('detail', '请选择信用卡支持期数', false);
		isCorrect = false;
	}
	
	return isCorrect;
}

<%-- 清空提示 --%>
function cleanTip() {
	$("span:[id^=Tip_]").hide();
	$("span:[id^=Tip_]").text('');
}
<%-- 附加提示 --%>
function appendTip(id, msg, isFocus) {
	if( !(isFocus == true || isFocus == false) ) 
		isFocus = true;
	
	var target = $('#Tip_' + id);
	if(target.text().length > 0) {
		appendWord(target, msg);
	} else
		target.text(msg);
	target.show();
	if(isFocus)
		$('#' + id).focus();
}

function appendWord(origin, apptext){
	if(origin.text().length==0){
		origin.text(apptext);
	}else{
		origin.text(origin.text()+', '+apptext);
	}
}
</script>

<s:if test="hasErrors()">
<p><s:actionerror cssClass="msg rn" /></p>
</s:if>
<s:if test="hasActionMessages()">
<p><s:actionmessage cssClass="msg rn" /></p>
</s:if>
<s:if test="hasFieldErrors()">
<p><s:fielderror cssClass="msg rn" /></p>
</s:if>

<h1>银行分期基本设置</h1>
<s:form action="setting/save.do" namespace="/creditcard" method="post" id="creditcardForm" name="creditcardForm" >
<table width="100%" border="0" cellspacing="0" cellpadding="0" class="creditcard">
	<tr>
		<th><span class="txt-rd">＊</span>信用卡银行：</th>
		<td>
			<s:select id="bankCode" name="bankCode" list="bankMenu.options" listKey="key" listValue="value.name" headerKey="" headerValue="" ></s:select>
			<s:hidden id="bankId" name="bankId" />
			<s:hidden id="creditcardName" name="creditcardName" />
			<br/><span id="Tip_creditcardName" class="msg rn" style="display:none;"></span>
		</td>
	</tr>
	<tr>
		<th><span class="txt-rd">＊</span>分期设置：</th>
		<td>
			<table width="100%" border="0" cellpadding="0" cellspacing="0" class="tb-05">
				<tr>
					<th>
						<span class="creditcard-dtl-1">支持期数</span>
						<span class="creditcard-dtl-2">会员自付手续费(%)</span>
						<span class="creditcard-dtl-3">交易金额上下限</span>
					</th>
				</tr>
				<tr>
					<td align="center">
						<s:iterator value="periodMenu.options" var="option" status="idx" >
							<s:set name="i" value="%{#idx.index}" />
							<s:set name="no" value="%{#i + 1}" />
						<p>
							<label class="creditcard-dtl-1">
								<input type="checkbox" id="tmp_periods_${no}" value="${option.key}" ${option.key==periods[i]?'checked':''} tabindex="${no}1" /> ${option.value.name}
								<s:hidden id="periods_%{#no}" name="periods[%{i}]" /> 
							</label>
							<label class="creditcard-dtl-2">
								<s:textfield id="fees_%{#no}" name="fees[%{i}]" tabindex="%{#no}2" />
							</label>
							<label class="creditcard-dtl-3">
								<s:textfield id="downLimits_%{#no}" name="downLimits[%{i}]" tabindex="%{#no}3" size="5" />
								~ 
								<s:textfield id="upLimits_%{#no}" name="upLimits[%{i}]" tabindex="%{#no}4" size="5" />
							</label>
						</p>
						</s:iterator>
						<p>
							<span id="Tip_detail" class="msg rn" style="display:none;"></span>
						</p>
					</td>
				</tr>
			</table>
		</td>
	</tr>
</table>
<p class="f-link"><a id="subBtn" href="#" tabindex="99" >储存</a> <%-- <a href="search.do" tabindex="100" >回查询列表</a></p> --%>
</s:form>